app.controller('docCtrl', function($scope, $http,$location, backendSrv){

    $scope.clear = function(){
        init();
    }

    var listDocsCb = function(data){
        $scope.docs = data;
        $scope.cats = _.keys($scope.docs); // categories
    }


    $scope.listDocs = function(){
        backendSrv.listDocs(listDocsCb);
    }

    $scope.downloadDoc = function(doc){
        alert('downloading doc: '+doc);
        //$location.path('/docs/download/'+doc).replace();
    }
    
    function init(){
        $scope.listDocs();
    }

    init();

    $scope.getUsers = function(){
        backendSrv.cmd('/admin/cmd', {cmd:'getUsers', roles:['admin']}, 
                function(data){$scope.users = data;});
    }
    $scope.deleteUsers = function(){
        backendSrv.cmd('/admin/cmd', {cmd:'deleteUsers'}, 
                function(data){$scope.users = data;});
    }
    $scope.addUsers = function(){
        backendSrv.cmd('/admin/cmd', {cmd:'addUsers'}, 
                function(data){$scope.users = data;});
    }

});
